package com.ustarlink.graphicsandanimations;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        LinearLayout container = (LinearLayout) findViewById(R.id.scaledImageContainer);
        ImageView originalImage = (ImageView) findViewById(R.id.originalImageHolder);

        Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.jellybean_statue);
        originalImage.setImageBitmap(bitmap);

        for (int i = 2; i < 10; i++){
            addScaledImageView(bitmap, i, container);
        }
    }

    private void addScaledImageView(Bitmap bitmap, int sampleSize, LinearLayout container) {

        BitmapFactory.Options bitmapOptions = new BitmapFactory.Options();
        bitmapOptions.inSampleSize = sampleSize;

        Bitmap scaledBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.jellybean_statue);

        ImageView scaledImageView = new ImageView(this);
        scaledImageView.setLayoutParams(new ViewGroup.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT));
        scaledImageView.setImageBitmap(scaledBitmap);

        container.addView(scaledImageView);

    }
}
